
<form class="form-inline" method="get">





    <div class="form-group col-xs-2">

        <button type="button" class="btn btn-primary" onclick="modal('{:url(\'add\')}','添加顶级组织结构')">
            添加顶级组织结构
        </button>
    </div>
</form>

<hr>

{volist name="depart" id="item1"}
<div class="accordion" id="category_{$item1.id}" role="tablist" aria-multiselectable="true">
    <div class="panel" style="background: none; border: none; -webkit-box-shadow: none; box-shadow: none;">
        <div class="panel-heading" style="background: none; border: 1px solid #ebebeb;">
            <i class="fa fa-plus" role="tab" id="category_header_{$item1.id}" data-toggle="collapse"
               data-parent="#category_{$item1.id}" href="#category_collapse_{$item1.id}"
               aria-expanded="false" aria-controls="category_collapse_{$item1.id}"
               onclick="collapseCategory('category_header_{$item1.id}','{$item1.id}')"></i>
            <span class="panel-title">【ID：{$item1.id}】{$item1.title}</span>
            <div style="float: right; margin-top: -4px;">

                <button type="button" class="btn btn-default btn-sm" onclick="modal('{:url(\'add\',array(\'parent_id\'=>$item1[\'id\']))}','添加下级组织结构')">
                    <i class="fa fa-plus"></i>
                </button>

                <button type="button" class="btn btn-default btn-sm" onclick="modal('{:url(\'edit\',array(\'id\'=>$item1[\'id\']))}','编辑组织结构')">
                    <i class="fa fa-edit"></i>
                </button>

                <button type="button" class="btn btn-default btn-sm department_delbtn" data-id="{$item1.id}"
                        data-title="{$item1.title}">
                    <i class="fa fa-times"></i>
                </button>

            </div>
        </div>
        <div id="category_collapse_{$item1.id}" class="panel-collapse collapse" role="tabpanel"
             aria-labelledby="category_header_{$item1.id}" aria-expanded="true" style="height: 0px;">
            <div id="depart_ment_con_{$item1.id}" class="panel-body" style="padding-right: 0;">

            </div>
        </div>
    </div>
</div>
{/volist}
<div class="row">
    <div class="col-xs-12" style="text-align: right;">
        {$depart->render()}
    </div>
</div>
<script>
    function collapseCategory(objectId,id)
    {
        var object = $("#"+objectId);
        //减号变加号
        if (object.hasClass("fa-minus"))
        {
            object.removeClass("fa-minus");
            object.addClass("fa-plus");
        }else if (object.hasClass("fa-plus"))
        {
            object.removeClass("fa-plus");
            object.addClass("fa-minus");
            $.ajax({
                url: "{:url('index')}",
                type: 'POST', //GET
                async: true,    //或false,是否异步
                data: {
                    id:id
                },
                timeout: 5000,    //超时时间
                dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                success: function (data) {
                    if(data.status==1){
                        showErrorMessage(data.info);
                        //console.log(data);
                    }else{
                        $("#depart_ment_con_"+id).html(data.data);
                    }

                }
            });

        }
    }
	$(function(){
		$("body").on("click",".department_delbtn",function(){
			var delid = $(this).attr('data-id');
			var deltitle = $(this).attr('data-title');
			var confim_msg = '确认删除 组织结构 【'+deltitle+'】？若有下级组织结构将一并删除，若有归属此组织结构会员，将无法匹配，请谨慎操作！';
			layer.confirm(confim_msg, {
				btn : [ '确定', '取消' ]//按钮
			}, function(index) {
				layer.close(index);
				//此处请求后台程序，下方是成功后的前台处理……
                var url = '/Department/remove/id/'+delid;
                $.ajax({
                    url: url,
                    type: "GET",
                    dataType: "JSON",
                    success: function (json)
                    {
                        if (json.status == 0)
                        {   showSuccessMessage(json.info, function () {
                            location.reload(true);
                        });

                        }
                        else
                        {
                            showErrorMessage(json.info);
                        }
                    },
                    error: function (result)
                    {
                        showErrorMessage("操作失败！");
                    }
                });
			}); 
		});
	});
</script>